package exception;

/**
 * Finally面试题
 */

public class FinallyDemo3 {
    public static void main(String[] args) {
        System.out.println(test("0")+","+test(null)+","+test(""));//3,3,3
    }
     public static int test(String str){
         try{
             System.out.println("执行了一次test方法,参数str:"+str);
             return str.charAt(0)-'0';
         }catch(NullPointerException e){
             System.out.println("出现了空指针!");
             return 1;
         }catch(Exception e){
             System.out.println("出现了其他异常");
             return 2;
         }finally{
             System.out.println("finally的代码执行了!");
         }
     }
}
